/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Server;

import data.AccessDB;
import data.ConexionBD;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Fco. Molpeceres Blázquez
 */
public class ClientThread extends Thread{
    
    Socket cliente;
    String estadoConexionBBDD;
    
    public ClientThread(Socket cliente){
        this.cliente = cliente;
    }
    
    @Override
    public void run(){
        System.out.println("Datos socket Servidor: " + cliente.getLocalSocketAddress());
        System.out.println("Datos socket Cliente: " + cliente.getRemoteSocketAddress());
        AccessDB lecturaBD = new AccessDB();
        ConexionBD conexionBD = new ConexionBD();
        estadoConexionBBDD = conexionBD.connect();
        OutputStream flujoSalida;
        try {
            flujoSalida = cliente.getOutputStream();
            DataOutputStream salidaDatos = new DataOutputStream(flujoSalida);
            salidaDatos.writeUTF(estadoConexionBBDD);
            salidaDatos.close();
            flujoSalida.close();
        } catch (IOException ex) {
            Logger.getLogger(ClientThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
